﻿using DocumentFormat.OpenXml.Lite.Helper;
using DocumentFormat.OpenXml.Lite.Xml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace DocumentFormat.OpenXml.Lite.WordprocessingML.Word.Style.StyleElements
{
    [XmlRoot("rsid", Namespace = Constants.WordMain)]
    public class RevisionIdentifier : XmlSerializable, IStyleElement
    {
        /// <summary>
        /// Hexadecimal value. Length: 8
        /// </summary>
        [XmlAttribute("val", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public string Value
        {
            get { return this.value; }
            set
            {
                if (value == null || value.Length != 8 ||
                     !Helpers.ParseHexadecimalValue(value))
                {
                    throw new ArgumentException("String: " + value +
                        "is not a valid hexadecimal string or length is not 8!");
                }

                this.value = value;
            }
        }

        [XmlIgnore]
        private string value;

        public RevisionIdentifier() { }

        public RevisionIdentifier(string value)
        {
            this.Value = value;
        }

        public void Copy(object obj)
        {
            if (obj is RevisionIdentifier)
            {
                this.Value = (obj as RevisionIdentifier).Value;
            }
        }
    }
}
